class formatStringChain {
    constructor(origin) {
        this.origin = origin
    }
    fillWithZeros() {

    }
}

class formatString {
    static fillWithZeros(origin, length, position = true) {
        origin = String(origin)
        return length - origin.length > 0
            ? (position
                ? '0'.repeat(length - origin.length) + origin
                : origin + '0'.repeat(length - origin.length))
            : origin
    }
    static fillWithSpace(origin, length, position = true) {
        origin = String(origin)
        return length - origin.length > 0
            ? (position
                ? ' '.repeat(length - origin.length) + origin
                : origin + ' '.repeat(length - origin.length))
            : origin
    }
    static print(template, ...values) {
        let placeholder = template.match(/%s/g).length
        // 如果占位符个数少余等于传进来的值得个数
        if (placeholder <= values.length) {
            for (let index = 0; index < placeholder; index++) {
                template = template.replace(/%s/, values[index])
            }
        }
        // 如果占位符个数多于传进来的值得个数
        else {
            values.forEach(item => {
                template = template.replace(/%s/, item)
            })
        }
        return template
    }

}

console.log(formatString.print("我们用%s的%s来模仿%s的%s函数功能", 'JavaScript', '正则表达式', 'C语言', 'print'))